package com.scs.application.modules.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.query.QueryContext;
import com.scs.application.core.query.QueryContextHolder;
import com.scs.application.modules.dept.entity.ApplyAuto;
import com.scs.application.modules.sys.model.PageResult;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.base.service.MatrCategoryService;
import com.scs.application.modules.base.entity.MatrCategory;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 */
@RestController
@RequestMapping("/base/matr_category")
public class MatrCategoryController extends CrudController<MatrCategoryService, MatrCategory>{



    /**
     * 选择 耗材分类视图
     */
    @GetMapping("/pageWithCategory")
    public PageResult pageForSelect(@RequestParam Map<String, Object> reqData) {
        QueryContext queryContext = QueryContextHolder.currentContext();
        IPage pageResult = service.pageWithCategory(queryContext);
        return PageResult.ok("查询成功", pageResult.getRecords(), pageResult.getTotal());
    }


    //分类列表
    @GetMapping("/getCategoryUk")
    public RestResult<List> getCategoryUk() {
        QueryContext queryContext = QueryContextHolder.currentContext();
        Map<String, Object> mapParam = queryContext.getParams();

        QueryWrapper queryWrapper = Wrappers.<ApplyAuto>query();
        queryWrapper.select("id as value,category_name as label");
        queryWrapper.orderByAsc("category_name");

        //过滤时间区间
        if (mapParam != null && mapParam.get("gmtApply") !=null){
//            Object[] gmtApplyArr = (Object[]) mapParam.get("gmtApply");
//            if (gmtApplyArr.length == 2) {
//                queryWrapper.between("gmt_apply",gmtApplyArr[0],gmtApplyArr[1] );
//            }
        }

        List<Map<String, Object>> list = service.listMaps(queryWrapper );
        return RestResult.ok("查询成功", list);
    }
}
